<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function add_interest_rating_history($object_id, $user_id, $rating, $timestamp) {
    if(!$object_id || !$user_id)
        return FALSE;
    $query = "INSERT INTO interest_ratings_history (object_id, user_id, rating, timestamp)
                VALUES ('$object_id', '$user_id', '$rating', '$timestamp')";
    return safe_insert_query($query);
}

function get_interest_rating_history($id) {
    $query = "SELECT id, object_id, user_id, rating, timestamp FROM interest_ratings_history WHERE id = '$id'";
    $result = safe_select_query($query);
    return $result[0];
}

function get_interest_ratings_history_of($user_id) {
    $query = "SELECT id, object_id, rating, user_id, timestamp FROM interest_ratings_history WHERE user_id = '$user_id' ORDER BY id DESC";
    return safe_select_query($query);
}

function get_interest_ratings_history_on($object_id) {
    $query = "SELECT id, user_id, rating, timestamp FROM interest_ratings_history WHERE object_id = '$object_id'";
}

function get_interest_ratings_history($object_id, $user_id) {
    $query = "SELECT * FROM interest_ratings_history WHERE object_id = '$object_id' AND user_id = '$user_id' ORDER BY id DESC";
    return safe_select_query($query);
}

function delete_interest_ratings_history($object_id, $user_id) {
    $query = "DELETE FROM opinions_streams WHERE ref_id IN (SELECT id FROM interest_ratings_history WHERE object_id = '$object_id' AND user_id = '$user_id')";
    //echo $query;
    safe_delete_query($query);
    $query = "DELETE FROM interest_ratings_history WHERE object_id = '$object_id' AND user_id = '$user_id'";
    return safe_delete_query($query);
}

?>
